import { Message } from 'element-ui'
import ie from './ie'
import { beforeRemoveCol, beforeRemoveRow, afterCreateCol, afterCreateRow } from './transactionUndoRedo'
import { uniqby, isequal, cloneDeep } from "lodash";
import { qr_base64, br_base64 } from './base64'
import { decode } from 'js-base64'
const borderColors = [{
  name: "FFFFFF",
  rgb: [255, 255, 255]
}, {
  name: "000000",
  rgb: [0, 0, 0]
}, {
  name: "EEECE1",
  rgb: [238, 236, 225]
}, {
  name: "1F497D",
  rgb: [31, 73, 125]
}, {
  name: "4F81BD",
  rgb: [79, 129, 189]
}, {
  name: "C0504D",
  rgb: [192, 80, 77]
}, {
  name: "9BBB59",
  rgb: [155, 187, 89]
}, {
  name: "8064A2",
  rgb: [128, 100, 162]
}, {
  name: "4BACC6",
  rgb: [75, 172, 198]
}, {
  name: "F79646",
  rgb: [247, 150, 70]
}, {
  name: "F2F2F2",
  rgb: [242, 242, 242]
}, {
  name: "7F7F7F",
  rgb: [127, 127, 127]
}, {
  name: "DDD9C3",
  rgb: [221, 217, 195]
}, {
  name: "C6D9F0",
  rgb: [198, 217, 240]
}, {
  name: "DBE5F1",
  rgb: [219, 229, 241]
}, {
  name: "F2DCDB",
  rgb: [242, 220, 219]
}, {
  name: "EBF1DD",
  rgb: [235, 241, 221]
}, {
  name: "E5E0EC",
  rgb: [229, 224, 236]
}, {
  name: "DBEEF3",
  rgb: [219, 238, 243]
}, {
  name: "FDEADA",
  rgb: [253, 234, 218]
}, {
  name: "D8D8D8",
  rgb: [216, 216, 216]
}, {
  name: "595959",
  rgb: [89, 89, 89]
}, {
  name: "C4BD97",
  rgb: [196, 189, 151]
}, {
  name: "8DB3E2",
  rgb: [141, 179, 226]
}, {
  name: "B8CCE4",
  rgb: [184, 204, 228]
}, {
  name: "E5B9B7",
  rgb: [229, 185, 183]
}, {
  name: "D7E3BC",
  rgb: [215, 227, 188]
}, {
  name: "CCC1D9",
  rgb: [204, 193, 217]
}, {
  name: "B7DDE8",
  rgb: [183, 221, 232]
}, {
  name: "FBD5B5",
  rgb: [251, 213, 181]
}, {
  name: "BFBFBF",
  rgb: [191, 191, 191]
}, {
  name: "3F3F3F",
  rgb: [63, 63, 63]
}, {
  name: "938953",
  rgb: [147, 137, 83]
}, {
  name: "548DD4",
  rgb: [84, 141, 212]
}, {
  name: "95B3D7",
  rgb: [149, 179, 215]
}, {
  name: "D99694",
  rgb: [217, 150, 148]
}, {
  name: "C3D69B",
  rgb: [195, 214, 155]
}, {
  name: "B2A2C7",
  rgb: [178, 162, 199]
}, {
  name: "92CDDC",
  rgb: [146, 205, 220]
}, {
  name: "FAC08F",
  rgb: [250, 192, 143]
}, {
  name: "A5A5A5",
  rgb: [165, 165, 165]
}, {
  name: "262626",
  rgb: [38, 38, 38]
}, {
  name: "494429",
  rgb: [73, 68, 41]
}, {
  name: "17365D",
  rgb: [23, 54, 93]
}, {
  name: "366092",
  rgb: [54, 96, 146]
}, {
  name: "953734",
  rgb: [149, 55, 52]
}, {
  name: "76923C",
  rgb: [118, 146, 60]
}, {
  name: "5F497A",
  rgb: [95, 73, 122]
}, {
  name: "31849B",
  rgb: [49, 132, 155]
}, {
  name: "E36C09",
  rgb: [227, 108, 9]
}, {
  name: "7F7F7F",
  rgb: [127, 127, 127]
}, {
  name: "0C0C0C",
  rgb: [12, 12, 12]
}, {
  name: "1D1B10",
  rgb: [29, 27, 16]
}, {
  name: "0F243E",
  rgb: [15, 36, 62]
}, {
  name: "244061",
  rgb: [36, 64, 97]
}, {
  name: "632423",
  rgb: [99, 36, 35]
}, {
  name: "4F6128",
  rgb: [79, 97, 40]
}, {
  name: "3F3151",
  rgb: [63, 49, 81]
}, {
  name: "205867",
  rgb: [32, 88, 103]
}, {
  name: "984806",
  rgb: [152, 72, 6]
}, {
  name: "C00000",
  rgb: [192, 0, 0]
}, {
  name: "FF0000",
  rgb: [255, 0, 0]
}, {
  name: "FFC000",
  rgb: [255, 192, 0]
}, {
  name: "FFFF00",
  rgb: [255, 255, 0]
}, {
  name: "92D050",
  rgb: [146, 208, 80]
}, {
  name: "00B050",
  rgb: [0, 176, 80]
}, {
  name: "00B0F0",
  rgb: [0, 176, 240]
}, {
  name: "0070C0",
  rgb: [0, 112, 192]
}, {
  name: "002060",
  rgb: [0, 32, 96]
}, {
  name: "7030A0",
  rgb: [112, 48, 160]
}]
const fontSizes = [8, 9, 10, 11, 12, 13, 14, 15, 16, 18, 20, 22, 24, 26, 28, 36, 48, 72]
const fontFamilys = [{
  name: "Calibri",
  family: "Calibri"
}, {
  name: "仿宋",
  name1: "FangSong",
  family: "FangSong"
}, {
  name: "宋体",
  name1: "SimSun",
  family: "SimSun"
}, {
  name: "隶书",
  name1: "LiSu",
  family: "LiSu"
}, {
  name: "楷体",
  name1: "KaiTi",
  family: "KaiTi"
}, {
  name: "新宋体 ",
  name1: "NSimSun",
  family: "NSimSun"
}, {
  name: "黑体",
  name1: "SimHei",
  family: "SimHei"
}, {
  name: "微软雅黑",
  name1: "Microsoft YaHei",
  family: "MicrosoftYaHei"
}]
const trim = (e) => {
  return e && (e + '').replace(/ /g, '&nbsp;')
}
const is = (e, t) => {
  if (Array.isArray(e))
    return e;
  if (Symbol.iterator in Object(e))
    return function (e, t) {
      var n = []
        , o = !0
        , r = !1
        , i = undefined;
      try {
        for (var a, s = e[Symbol.iterator](); !(o = (a = s.next()).done) && (n.push(a.value),
          !t || n.length !== t); o = !0)
          ;
      } catch (l) {
        r = !0,
          i = l
      } finally {
        try {
          !o && s["return"] && s["return"]()
        } finally {
          if (r)
            throw i
        }
      }
      return n
    }(e, t);
  throw new TypeError("Invalid attempt to destructure non-iterable instance")
}
import handsontableHelper from './handsontableHelper'
export default class Excel {
  static borderColors = borderColors
  static fontSizes = fontSizes
  static fontFamilys = fontFamilys
  static widthHeightArea = {
    defaultRowHeight: 24,
    defaultColWidth: 100
  }
  static handsontableHelper = null
  //右侧配置面板 1全局配置 2二维码配置 3条码配置 4日期 5时间 6金额 7数值
  static rightPanelInfo = {
    rightVisible: false,
    type: 1
  }
  //Handsontable实例
  static hotInstance = null;
  // table选择区域
  static selectedRange = null
  // 当前选中cell的信息 用来操作单元格ni
  static selectCellInfo = null
  // toolbar下面显示选中单元格的信息
  static cellInfo = { cell: null, data: "" }
  // 左侧拖拽状态
  static ifAddVal = false
  // 打印线延时器
  static addReferenceTime = null
  // 打印配置
  static pageSetting = {
    size: 'A4',
    layout: 'vertical',
    customize: {
      width: 0,
      height: 0
    }
  }
  // 正则
  static alignDirectionRegExp = /font-text-align-(left|center|right)/
  static indentClsRegExp = /indent-(left|right)-(\d+)/
  // 是否编辑过表格
  static isHandsonTableEdited = false
  // 监听事件合集
  static emitter = {}

  // 历史config
  static undoIndex = 0
  static UndoRedoList = []
  static redoList = []
  static isUndoRedo = false
  static doneActionsAfterLast = null
  static ToolbarHelper = null
  // 注入监听事件
  static injectListener(funName, fun) {
    this.emitter[funName] = fun
  }
  //初始实例 添加监听事件
  static init(el, Handsontable, json) {
    let data = null
    try {
      data = JSON.parse(decode(json))
    } catch (error) { }
    let config = {
      rowHeaders: true,
      colHeaders: true,
      manualColumnResize: true, // 手工更改列距
      manualRowResize: true, // 手动更改行距
      allowHtml: true,
      minCols: 26, // 最小列数
      minRows: 100,
      colws: data && data.colws ? data.colws.map(function (e) {
        return e ? parseInt(e, 10) : 100
      }) : [],
      rowhs: data && data.rowhs ? data.rowhs.map(function (e) {
        return e ? parseInt(e, 10) : 24
      }) : [],
      // colWidths: data && data.colws ? data.colws.map(function (e) {
      //   return e ? parseInt(e, 10) : 100
      // }) : [],
      // rowHeights: data && data.rowhs ? data.rowhs.map(function (e) {
      //   return e ? parseInt(e, 10) : 24
      // }) : [],
      cellHeight: "auto",
      selectionMode: 'range',
      cells: function (e, t, n) {
        this.renderer = 'styleRender'
        const o = this.instance.getSettings().cellWithField
        if (o && o[e + ':' + t]) {
          return {
            readOnly: !0
          }
        }
        const brCode = this.instance.getSettings().cellWithBRcode
        if (brCode && brCode[e + ':' + t]) {
          return {
            readOnly: !0
          }
        }
        const qrCode = this.instance.getSettings().cellWithQRcode
        if (qrCode && qrCode[e + ':' + t]) {
          return {
            readOnly: !0
          }
        }
        const r = this.instance.getSettings().cellWithImg
        return r && r[e + ':' + t]
          ? {
            readOnly: !0
          }
          : {
            readOnly: !1
          }

      },
      contextMenu: {
        callback(key, selection, clickEvent) {
          // Common callback for all options
          // console.log(key, selection, clickEvent)
        },
        items: {
          row_above: { name: '向上插入行' },
          col_left: { name: '向左插入列' },
          remove_row: { name: '删除行' },
          remove_col: { name: '删除列' },
          empty: {
            name: '清除内容',
            callback: (t, n) => {
              var r = {
                startRow: n[0].start.row,
                endRow: n[0].end.row,
                startCol: n[0].start.col,
                endCol: n[0].end.col
              };
              switch (t) {
                case 'empty':
                  this.clearContent(r)
                  break;
                default:
                  break;
              }
            }
          }
          // copy: { name: '复制' },
          // cut: { name: '剪切' },
          // about: {
          //   // Own custom option
          //   name() {
          //     // `name` can be a string or a function
          //     return '设置日期格式' // Name can contain HTML
          //   },
          //   hidden() {
          //     // `hidden` can be a boolean or a function
          //     // Hide the option when the first column was clicked
          //     return this.getSelectedLast()[1] === 0 // `this` === hotInstance
          //   },
          //   callback(key, selection, clickEvent) {
          //     // Callback for specific option
          //     setTimeout(() => {
          //       alert('Hello world!') // Fire alert after menu close (with timeout)
          //     }, 0)
          //   }
          // }
        }
      },
      language: 'zh-CN',
      licenseKey: 'non-commercial-and-evaluation',
      mergeCells: data && data.mergeCells || [],
      metaObjects: data && data.metaObjects || [],
      cellWithField: data && data.cellWithField || {},
      cellWithQRcode: data && data.cellWithQRcode || {},
      cellWithBRcode: data && data.cellWithBRcode || {},
      cellWithImg: data && data.cellWithImg || {},
      expressions: data && data.Expressions || [],
      filters: data && data.Filters || [],
      pageSetting: data && data.pageSetting || this.pageSetting,
      enableGridLine: true,
      undo: true,
      serviceKey: data && data.serviceKey || '',
      data: [[]],
      outsideClickDeselects: false, //在网格外单击鼠标，保留当前选择
      customFieldList: data && data.customFieldList || [], //用户自定义的字吨
    }
    if (data) {
      // 填充cell单元格数据
      var t = this.decodeCompressData(data.compressCellDatas, data.contentEdge);
      // 填充单元格border
      this.decodeCompressCellBorderStyle(data.cell || null, data.borders || {})
      config = Object.assign({}, data, config, {
        data: t
      })
    }
    Handsontable.renderers.registerRenderer('styleRender', this.styleRender)
    this.hotInstance = new Handsontable(el, {
      ...config
    })

    this.hotInstance.updateSettings({
      colWidths: (e) => {
        var t = this.hotInstance && this.hotInstance.getSettings().colws || null;
        return t && t[e] ? t[e] : this.widthHeightArea.defaultColWidth
      },
      rowHeights: (e) => {
        var t = this.hotInstance && this.hotInstance.getSettings().rowhs || null;
        return t && t[e] ? t[e] : this.widthHeightArea.defaultRowHeight
      },
    })
    this.hotInstance.transactionUndoRedo = {
      beforeRemoveCol,
      beforeRemoveRow,
      afterCreateCol,
      afterCreateRow
    },
      this.hotInstance.addHook("afterChange", (e, n) => {
        console.log(n, 'nnnnn');
        this.emitter['toggleDisableToolbarItems'] && typeof this.emitter['toggleDisableToolbarItems'] === 'function' && this.emitter['toggleDisableToolbarItems'](false)
        "edit" === n && (this.isHandsonTableEdited = !0)
        if (this.isUndoRedo && "UndoRedo.undo" !== n && "UndoRedo.redo" !== n && "UndoRedo.Undo" !== n && "populateFromArray" !== n) {
          const undo = this.hotInstance.undo
          const redo = this.hotInstance.redo
          this.hotInstance.runHooks("afterChangeSetDone", redo, undo, true)
        }
      })
    // 监听鼠标over事件，用于拖拽变量
    this.hotInstance.addHook('afterOnCellMouseOver', (event, cellCoords) => {
      this.currentMouseOverCell = cellCoords
      if (this.ifAddVal) {
        this.hotInstance.selectCell(cellCoords.row, cellCoords.col)
      }
    })
    this.hotInstance.addHook("afterChangeGridLineState", (t) => {
      var n = "no-gridlines"
        , o = this.hotInstance.rootElement;
      t ? o && o.classList.remove(n) : o && o.classList.add(n),
        this.hotInstance.updateSettings({
          enableGridLine: t
        })
    })
    // 获取所选区域单元格数组 当前高亮
    this.hotInstance.addHook('afterSelectionEnd', (row, column, row2, column2, selectionLayerLevel) => {
      if (!this.hotInstance.getActiveEditor() || !this.hotInstance.getActiveEditor()._opened) {
        this.selectedRange = {
          startRow: row,
          startCol: column,
          endRow: row2,
          endCol: column2
        }
        this.updateCellUnit(this.selectedRange)
        this.syncToolbarState(this.selectedRange)
      }
    })
    this.hotInstance.addHook('afterOnCellMouseDown', (event, c, td) => {
      this.parseCellInfo(c)
    })
    //记录改变历史
    this.hotInstance.addHook("afterChangeSetDone", (e, n, isUndoRedo = false) => {
      this.redoList = []
      if (this.doneActionsAfterLast && ["insert_row", "insert_col", "remove_row", "remove_col"].includes(this.doneActionsAfterLast.actionType)) {
        const redo = this.hotInstance.redo.bind(this)
        const undo = this.hotInstance.undo.bind(this)
        this.UndoRedoList.unshift({ applyChange: [redo, e], revertChange: [undo, n], isUndoRedo })
        this.doneActionsAfterLast = null
      } else {
        this.UndoRedoList.unshift({ applyChange: e, revertChange: n, isUndoRedo })
      }
      this.ToolbarHelper && this.ToolbarHelper.calculateEnable()
    })
    //在更改撤消堆栈后由UndoRedo插件触发。
    this.hotInstance.addHook("afterUndoStackChange", (doneActionsBefore, doneActionsAfter) => {
      this.doneActionsAfterLast = doneActionsAfter[doneActionsAfter.length - 1]
    })
    //改变列宽度
    this.hotInstance.addHook('afterColumnResize', (e, n) => {
      this.updateColumnWidth(e, n)
    })
    //改变行宽度
    this.hotInstance.addHook('afterRowResize', (e, n) => {
      this.updateRowHeight(e, n)
    })
    // 复制💰
    this.hotInstance.addHook('beforePaste', (e, n) => {
      this.isUndoRedo = true
    })

    //编辑状态不能选中toolbar
    this.hotInstance.addHook('afterBeginEditing', (e, n) => {
      this.isUndoRedo = true
      this.emitter['toggleDisableToolbarItems'] && typeof this.emitter['toggleDisableToolbarItems'] === 'function' && this.emitter['toggleDisableToolbarItems'](true)
    })
    //删除单元格逻辑
    this.hotInstance.addHook("beforeKeyDown", (e) => {
      let keyCode = e.keyCode
      let BaseEditor = this.hotInstance.getActiveEditor()
      if ((8 === keyCode || 46 === keyCode) && (!BaseEditor || !BaseEditor._opened)) {
        e.isImmediatePropagationEnabled = !1
        e.preventDefault()
        this.clearContent()
        window.isHandsonTableEdited = !0
      }
    })
    //新建行
    this.hotInstance.addHook('afterCreateRow', (n, o, r) => {
      if ("UndoRedo.undo" !== r && "UndoRedo.redo" !== r && "auto" !== r) {
        if (this.hotInstance.transactionUndoRedo && this.hotInstance.transactionUndoRedo.afterCreateRow) {
          var a = this.hotInstance.transactionUndoRedo.afterCreateRow(n, o, r, this.hotInstance, this.handsontableHelper);
          a.applyChange()
        }
      }
    })
    //删除行
    this.hotInstance.addHook('afterRemoveRow', (n, o, r, i) => {
      if ("UndoRedo.undo" !== i && "UndoRedo.redo" !== i && "auto" !== i) {
        var a = this.hotInstance.getSourceDataArray();
        n = (a.length + n) % a.length;
        if (this.hotInstance.transactionUndoRedo && this.hotInstance.transactionUndoRedo.beforeRemoveRow) {
          var c = this.hotInstance.transactionUndoRedo.beforeRemoveRow(n, o, i, this.hotInstance, this.handsontableHelper);
          c.applyChange()
        }
      }
    })
    //添加列
    this.hotInstance.addHook('afterCreateCol', (n, o, r) => {
      if ("UndoRedo.undo" !== r && "UndoRedo.redo" !== r && "auto" !== r) {
        if (this.hotInstance.transactionUndoRedo && this.hotInstance.transactionUndoRedo.afterCreateCol) {
          var a = this.hotInstance.transactionUndoRedo.afterCreateCol(n, o, r, this.hotInstance, this.handsontableHelper);
          a.applyChange()
        }
      }
    })
    //删除列
    this.hotInstance.addHook('afterRemoveCol', (n, o, r, i) => {
      if ("UndoRedo.undo" !== i && "UndoRedo.redo" !== i && "auto" !== i) {
        n = (this.hotInstance.countCols() + n) % this.hotInstance.countCols();
        if (this.hotInstance.transactionUndoRedo && this.hotInstance.transactionUndoRedo.beforeRemoveCol) {
          var m = this.hotInstance.transactionUndoRedo.beforeRemoveCol(n, o, i, this.hotInstance, this.handsontableHelper);
          m.applyChange()
        }
      }
    })
    // 添加打印线
    this.addReferenceTime = setInterval(this.addReferenceLine.bind(this), 500)
    setTimeout(() => {
      this.selectedRange = {
        startRow: 0,
        startCol: 0,
        endRow: 0,
        endCol: 0
      }
      this.select(this.selectedRange)
      this.updateCellUnit(this.selectedRange)
      this.syncToolbarState(this.selectedRange)
    }, 0)
    this.handsontableHelper = new handsontableHelper(this.hotInstance)

  }
  //自定义样式
  static styleRender(instance, td, row, col, prop, value, cellProperties) {
    const settings = instance.getSettings()
    const cellWithField = settings && settings.cellWithField
    const expressions = settings && settings.expressions
    const cellPos = row + ':' + col
    const Expression =
      cellWithField[cellPos] && cellWithField[cellPos].Expression
    const RootMetaDataID =
      cellWithField[cellPos] && cellWithField[cellPos].RootMetaDataID
    const filters = settings && settings.filters
    let hasCondition = false
    if (Expression) {
      var m = expressions.find(function (e) {
        return e.Expression === Expression
      });
      value = m && m.FieldLabel || "";
      var g = settings.metaObjects.find(function (e) {
        return e.MetaDataID === RootMetaDataID && e.IsMain
      });
      hasCondition = cellWithField[cellPos].FormatConfig || !g && filters.find(function (e) {
        return e.metaDataID === RootMetaDataID
      })
    }
    const cellWithImg = settings && settings.cellWithImg
    let cellWithImg_cellPos = cellWithImg && cellWithImg[cellPos]
    const cellWithBRcode = settings && settings.cellWithBRcode
    const cellWithQRcode = settings && settings.cellWithQRcode
    const QRcode = cellWithQRcode && cellWithQRcode[cellPos]
    const BRcode = cellWithBRcode && cellWithBRcode[cellPos]
    if (cellWithImg_cellPos) {
      value = cellWithImg_cellPos.ClientUrl
      td.innerHTML =
        '<div class="contains"><div class="tab"><img class="cell-img" src=' +
        value +
        ' style="position: absolute; max-height: 100%; top: 0;max-width:100%" /></div></div>'
    } else if (QRcode) {
      td.innerHTML = '<div class="contains"><img class="cell-img" src=' + qr_base64 + ' /></div>'
    } else if (BRcode) {
      td.innerHTML = '<div class="contains"><img class="cell-img" src=' + br_base64 + ' /></div>'
    } else {
      value = trim(value)
      td.innerHTML = value
        ? '<div class="contains"><div class="tab"><div class="data">' +
        value +
        '</div>' +
        (hasCondition ? '<span class="red-point"></span>' : '') +
        '</div></div>'
        : ''
    }
    td.className = cellProperties.className || ''
    cellProperties.style && Object.keys(cellProperties.style).forEach(function (e) {
      cellProperties.style[e] && (td.style[e] = cellProperties.style[e])
    })
    return td
  }
  //解析数据
  static decodeCompressData(e, t) {
    if (!e || !t)
      return [[]];
    var n = t.maxRow
      , o = t.maxCol;
    if (null === n && null === o)
      return [[]];
    for (var r = [], i = function (t) {
      for (var n = function (n) {
        if (r[t] || (r[t] = new Array(o + 1),
          r[t].fill(null, 0, o + 1)),
          Array.isArray(e)) {
          var i = e.find(function (e) {
            return e[t + ":" + n] !== undefined
          });
          i && (r[t][n] = i[t + ":" + n].isField ? null : i[t + ":" + n].content)
        } else {
          var a = e[t + ":" + n];
          a && (r[t][n] = a.isField ? null : a.content)
        }
      }, i = 0; i <= o; i++)
        n(i)
    }, a = 0; a <= n; a++)
      i(a);
    return r
  }
  //解析格式
  static decodeCompressCellBorderStyle(e) {
    var t = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
    if (!e || 0 === e.length)
      return null;
    for (var n = 0; n < e.length; n++)
      e[n].border && (e[n].border = t[e[n].border] || {})
  }
  //保存所有配置
  static saveAllSettings() {
    return new Promise((res, rej) => {
      let n = this.hotInstance.getSettings()
      console.log(n, 'getSettings');
      //校验全局配置必填项
      if (!n.serviceKey) {
        Message({
          showClose: true,
          message: '请配置全局配置的业务服务选项',
          type: 'warning'
        })
        this.togglePanelShow(true, 1)
        this.emitter['togglePanel'] && typeof this.emitter['togglePanel'] === 'function' && this.emitter['togglePanel']({ row: null, col: null }, {}, 1, true)
        return rej('请配置全局配置的业务服务选项')
      }
      //校验二维码条形码必填项
      if (!this.verifyQRorBRCells(n.cellWithQRcode, n.cellWithBRcode)) {
        return rej('请配置二维码/条形码')
      }

      let t = {
        data: this.hotInstance.getData(),
        cell: []
      };
      this.borders = Object.create({});
      this.hotInstance.getCellsMeta().filter((e) => {
        return e && e.style && Object.keys(e.style).length > 0 && !(1 === Object.keys(e.style).length && "init" === e.style.backgroundColor) || e && e.className && "" !== e.className.trim()
      }).forEach((n) => {
        t.cell.push({
          row: n.row,
          col: n.col,
          style: n.style ? n.style : {},
          className: n.className ? n.className.trim() : "",
          readOnly: !!n.readOnly && n.readOnly,
          border: this.compressCellBorderStyle(n.border, n.row + "-" + n.col)
        })
      });

      let o = Object.values(n.cellWithField) && Object.values(n.cellWithField).filter(function (e) {
        return e && e.hasOwnProperty("Expression")
      }).map(function (e) {
        return e.Expression
      })
      let r = uniqby(n.expressions, "Expression")
      let i = r && r.filter(function (e) {
        return o && o.indexOf(e.Expression) > -1
      })
      let a = function (e) {
        if (n.cellWithField.hasOwnProperty(e)) {
          let t = e.split(":")
          let o = is(t, 2)
          let r = o[0]
          let a = o[1];
          (Number.parseInt(r) < 0 || Number.parseInt(a) < 0 || !i.find(function (t) {
            return t.Expression === n.cellWithField[e].Expression
          })) && delete n.cellWithField[e]
        }
      };
      for (var s in n.cellWithField) {
        a(s);
      }
      let c = {
        expressions: i,
        filters: n.filters,
        cell: n.cell,
        colws: n.colws,
        data: n.data,
        mergeCells: this.calculateMergeCellRect(n.mergeCells, n.colws, n.rowhs, this.widthHeightArea.defaultColWidth, this.widthHeightArea.defaultRowHeight),
        pageSetting: n.pageSetting,
        rowhs: n.rowhs,
        cellHeight: n.cellHeight,
        cellWithField: n.cellWithField,
        cellWithQRcode: n.cellWithQRcode,
        cellWithBRcode: n.cellWithBRcode,
        cellWithImg: n.cellWithImg,
        enableGridLine: n.enableGridLine,
        defaultRowHeight: this.widthHeightArea.defaultRowHeight,
        defaultColWidth: this.widthHeightArea.defaultColWidth,
        borders: this.borders,
        serviceKey: n.serviceKey,
        customFieldList: n.customFieldList
      }
      let d = this.compressData(n.data, n.cellWithField, n.cellWithImg, n.cellWithQRcode, n.cellWithBRcode, t.cell, c.mergeCells);
      d.contentEdge.minRow = d.contentEdge.minRow === null ? 0 : d.contentEdge.minRow
      d.contentEdge.minCol = d.contentEdge.minCol === null ? 0 : d.contentEdge.minCol
      return res(Object.assign({}, c, t, d))
    })
  }
  static calculateMergeCellRect(mergeCells, colws, rowhs, defaultColWidth, defaultRowHeight) {
    if (mergeCells && mergeCells.length > 0)
      for (var i = 0; i < mergeCells.length; i++) {
        for (var a = mergeCells[i].row, s = mergeCells[i].col, l = 0, u = 0, c = 0; c < mergeCells[i].rowspan; c++) {
          u += rowhs[a + c] || defaultRowHeight;
        }
        for (var d = 0; d < mergeCells[i].colspan; d++) {
          l += colws[s + d] || defaultColWidth;
        }
        mergeCells[i].height = u;
        mergeCells[i].width = l
      }
    return mergeCells
  }
  static compressData(data, cellWithField, cellWithImg, qrCode, brCode) {
    var cell = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : []
    var mergeCells = arguments.length > 6 && arguments[6] !== undefined ? arguments[6] : []
    var i = {}
    var a = {
      maxRow: 0,
      maxCol: 0,
      minRow: null,
      minCol: null
    }
    var s = function (row, col) {
      a.maxRow < row && (a.maxRow = row),
        (null === a.minRow || a.minRow > row) && (a.minRow = row),
        a.maxCol < col && (a.maxCol = col),
        (null === a.minCol || a.minCol > col) && (a.minCol = col)
    }
    for (var l = 0; l < data.length; l++)
      for (var u = 0; u < data[l].length; u++)
        if (null !== data[l][u] && data[l][u] !== undefined && "" !== data[l][u] || cellWithField[l + ":" + u] || cellWithImg[l + ":" + u] || qrCode[l + ":" + u] || brCode[l + ":" + u]) {
          s(l, u);
          var c = l + ":" + u;
          i[c] = {}
          i[c].content = data[l][u]
          cellWithField[c] && (i[c].isField = !0)
          qrCode[c] && (i[c].isQR = !0)
          brCode[c] && (i[c].isBR = !0)
        }
    for (var d = 0; d < cell.length; d++)
      (cell[d].className && "" !== cell[d].className.trim() || 0 !== Object.keys(cell[d].style).length) && (cell[d].className.indexOf("border") > -1 || cell[d].style && cell[d].style.backgroundColor && "init" !== cell[d].style.backgroundColor) && s(cell[d].row, cell[d].col);
    for (var h = 0; h < mergeCells.length; h++)
      null === a.minRow ? a.minRow = mergeCells[h].row : a.minRow > mergeCells[h].row && (a.minRow = mergeCells[h].row),
        s(mergeCells[h].row + mergeCells[h].rowspan - 1, mergeCells[h].col + mergeCells[h].colspan - 1);
    return {
      compressCellDatas: i,
      contentEdge: a
    }
  }
  // 校验
  static verifyQRorBRCells(qr, br) {
    if (qr && "[object Object]" === Object.prototype.toString.call(qr)) {
      if (!this.judge(qr, '二维码')) {
        return false
      }
    }
    if (br && "[object Object]" === Object.prototype.toString.call(br)) {
      if (!this.judge(br, '条码')) {
        return false
      }
    }
    return true
  }
  static judge(obj, str) {
    for (let key in obj) {
      let [row, col] = key.split(":")
      row = Number(row)
      col = Number(col)
      const pos = (parseInt(Number(col) / 26) > 0 ? "A" : "") + String.fromCharCode(65 + (Number(col) < 26 ? Number(col) : Number(col) % 26)) + (Number(row) + 1)
      if (!obj[key].content) {
        Message({
          showClose: true,
          message: `请配置${pos}的${str}`,
          type: 'warning'
        })
        const range = this.handsontableHelper.getContainedMergeCells({
          startRow: row,
          endRow: row,
          startCol: col,
          endCol: col
        })
        let startRow = row,
          endRow = row,
          startCol = col,
          endCol = col
        if (range && range.length) {
          startRow = range.row || range[0].row
          endRow = (range.row + range.rowspan - 1) || (range[0].row + range[0].rowspan - 1)
          startCol = range.col || range[0].col
          endCol = (range.col + range.colspan - 1) || (range[0].col + range[0].colspan - 1)
        }
        this.select({ startRow, startCol, endRow, endCol })
        this.parseCellInfo({
          row: startRow,
          col: startCol
        })
        return false
      }
    }
    return true
  }
  //删除特殊cell清除内容
  static clearContent(e) {
    e || (e = this.handsontableHelper._defaultSelection(this.handsontableHelper.getSelection()));
    for (var n = [], o = [], r = e, i = r.startRow, a = r.endRow, s = r.startCol, l = r.endCol, u = i; u <= a; u++)
      for (var c = s; c <= l; c++)
        n.push([u, c, null]),
          this.handsontableHelper.forEachSelectedCellMeta((e) => {
            this.handsontableHelper.hasClass(e, "img-cell") && o.push(this.handsontableHelper.genNewCellMeta({
              row: e.row,
              col: e.col,
              className: this.handsontableHelper.removeClass(e, /img-cell/)
            }))
            this.handsontableHelper.hasClass(e, "QR-cell") && o.push(this.handsontableHelper.genNewCellMeta({
              row: e.row,
              col: e.col,
              className: this.handsontableHelper.removeClass(e, /QR-cell/)
            }))
            this.handsontableHelper.hasClass(e, "BR-cell") && o.push(this.handsontableHelper.genNewCellMeta({
              row: e.row,
              col: e.col,
              className: this.handsontableHelper.removeClass(e, /BR-cell/)
            }))
            if (this.rightPanelInfo.rightVisible) {
              this.togglePanelShow(false, 1)
              this.emitter['togglePanel'] && typeof this.emitter['togglePanel'] === 'function' && this.emitter['togglePanel']({
                row: e.row,
                col: e.col
              }, {}, 1, false)
            }
          });
    new ie(this.hotInstance, "clearContent", n).commit()
    new ie(this.hotInstance, "changeCellStyle", o, "command").commit()
  }

  static select(selectedRange) {
    selectedRange = selectedRange ? selectedRange : this.selectedRange
    selectedRange && this.hotInstance?.selectCell(selectedRange.startRow, selectedRange.startCol, selectedRange.endRow, selectedRange.endCol)
  }
  // 添加打印线
  static addReferenceLine() {
    let el = document.querySelector('.wtHider')
    if (el) {
      clearInterval(this.addReferenceTime)
      var t = document.createElement('div')
      t.className = 'paper_horizontal'
      t.style.left = '50px'
      el.appendChild(t)
      var n = document.createElement('div')
      n.className = 'paper_vertical'
      n.style.top = '27px'
      el.appendChild(n)
      this.calcReferenceLine()
    }
  }
  static calcReferenceLine() {
    const e = {
      dpi: 96,
      dpcm: 96 / 2.54
    }
    const t = e.dpi
    const sizeMap = {
      A4: {
        width: 210,
        height: 297
      },
      A3: {
        width: 297,
        height: 420
      },
      A5: {
        width: 148,
        height: 210
      },
      B5: {
        width: 176,
        height: 250
      },
      customize: this.pageSetting.customize
    }
    const o = {
      vertical: 13,
      horizontal: 11
    }
    let hor = document.querySelector('.paper_horizontal')
    let ver = document.querySelector('.paper_vertical')
    let size = this.pageSetting.size
    let layout = this.pageSetting.layout
    let l = 0
    let u = 0
    hor &&
      ver &&
      (layout == 'vertical'
        ? ((u = Math.ceil(((sizeMap[size].height - 2 * o.vertical) / 25.4) * t)),
          (l = Math.ceil(((sizeMap[size].width - 2 * o.horizontal) / 25.4) * t)))
        : ((u = Math.ceil(((sizeMap[size].width - 2 * o.horizontal) / 25.4) * t)),
          (l = Math.ceil(((sizeMap[size].height - 2 * o.vertical) / 25.4) * t))),
        (hor.style.top = 30 + (u > 0 ? u : 0) + 'px'),
        (ver.style.left = 50 + (l > 0 ? l : 0) + 'px'))
  }
  //清除鼠标hover保存的单元格信息
  static clearCurrentMouseOverCell() {
    this.currentMouseOverCell = null
  }
  static toggleAdd(ifAddVal) {
    this.ifAddVal = ifAddVal
  }
  //  拖拽设置单元cell
  static setCellsExpression(e, t) {
    if (!e || !Array.isArray(e) || e.length <= 0)
      return null;
    this.clearContent()
    new ie(this.hotInstance, "updateCellExpression", e, t).commit()
    this.updateCellUnit(this.selectedRange)
  }
  // 获取table基础设置options
  static getSettings() {
    return this.hotInstance ? this.hotInstance.getSettings() : {}
  }
  // 解析单元格配置
  static analysisCellMeta(meta) {
    if (!meta) return {}
    var styleObj = {
      fontFamily: 'SimSun',
      fontWeight: 'normal',
      fontSize: 11,
      textDecoration: 'none',
      fontStyle: 'none',
      textAlign: 'left',
      verticalAlign: 'center',
      borderTop: [],
      borderRight: [],
      borderBottom: [],
      borderLeft: []
    }
    var addBorderClass = function (e, pos) {
      var color =
        e.indexOf('-color-') > 0
          ? e.replace('border-' + pos + '-color-', '')
          : null
      var width =
        e.indexOf('-width-') > 0
          ? e.replace('border-' + pos + '-width-', '')
          : null
      var style =
        e.indexOf('-style-') > 0
          ? e.replace('border-' + pos + '-style-', '')
          : null
      switch (pos) {
        case 'top':
          color && (styleObj.borderTop[0] = color)
          width && (styleObj.borderTop[1] = parseInt(width))
          style && (styleObj.borderTop[2] = style)
          break
        case 'right':
          color && (styleObj.borderRight[0] = color)
          width && (styleObj.borderRight[1] = parseInt(width))
          style && (styleObj.borderRight[2] = style)
          break
        case 'bottom':
          color && (styleObj.borderBottom[0] = color)
          width && (styleObj.borderBottom[1] = parseInt(width))
          style && (styleObj.borderBottom[2] = style)
          break
        case 'left':
          color && (styleObj.borderLeft[0] = color)
          width && (styleObj.borderLeft[1] = parseInt(width))
          style && (styleObj.borderLeft[2] = style)
          break
      }
    }
    var classList = [
      {
        classText: 'fontFamily',
        classValue: 'font-family-'
      },
      {
        classText: 'fontWeight',
        classValue: 'font-weight-'
      },
      {
        classText: 'fontSize',
        classValue: 'font-size-'
      },
      {
        classText: 'textDecoration',
        classValue: 'text-decoration-'
      },
      {
        classText: 'fontStyle',
        classValue: 'font-style-'
      },
      {
        classText: 'textAlign',
        classValue: 'text-align-'
      },
      {
        classText: 'verticalAlign',
        classValue: 'vertical-align-'
      },
      {
        classText: 'fontWeight',
        classValue: 'font-weight-'
      }
    ]
    meta.split(' ').forEach(function (e) {
      if (e.indexOf('border-') < 0) {
        for (let i = 0; i < classList.length; i++) {
          if (e.indexOf(classList[i].classValue) == 0) {
            const classStr = e
            const classValue = classList[i].classValue
            styleObj[classList[i].classText] = classStr.replace(
              classValue,
              ''
            )
          }
        }
      } else {
        if (e.indexOf('border-top-') === 0) {
          addBorderClass(e, 'top')
        } else if (e.indexOf('border-right-') === 0) {
          addBorderClass(e, 'right')
        } else if (e.indexOf('border-bottom-') === 0) {
          addBorderClass(e, 'bottom')
        } else if (e.indexOf('border-left-') === 0) {
          addBorderClass(e, 'left')
        }
      }
    })
    return styleObj
  }
  // 更新选中单元格的信息，用于在页面显示
  static updateCellUnit(cell) {
    let n = cell.startRow
    let o = (cell.endRow, cell.startCol)
    let r = (cell.endCol, "");
    let t = (parseInt(o / 26) > 0 ? "A" : "") + String.fromCharCode(65 + (o < 26 ? o : o % 26)) + (n + 1)
    r = this.getExpressionCellText(n, o) || this.hotInstance.getDataAtCell(n, o) || ''
    this.cellInfo = {
      cell: t,
      data: r
    }
    this.emitter['updateCellUnit'] && typeof this.emitter['updateCellUnit'] === 'function' && this.emitter['updateCellUnit'](this.cellInfo)
  }
  // 获取选中单元格内容
  static getExpressionCellText(e, t) {
    var n = this.getCellExpression(e, t);
    return n ? n.FieldLabel || "" : null
  }
  //获取单元格变量信息
  static getCellExpression(e, t, n) {
    return n && "copy" === n ? this.handsontableHelper.getCellWithField(e, t) ? {
      fromCopy: !0,
      row: e,
      col: t
    } : null : this.handsontableHelper.getCellExpression(e, t)
  }
  static parseCellStyle() {
    var e = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : ""
      , t = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}
      , n = arguments.length > 2 && arguments[2] !== undefined && arguments[2]
      , o = e.split(/\s/gi).filter(function (e) {
        return "" !== e.trim()
      })
      , r = null;
    return (o || t || n) && (r = {}),
      o.forEach(function (e) {
        var t = new RegExp("(font)-(size|family|weight|style)-([^\\s]+)", "gi")
          , n = new RegExp("font-(text|vertical)-(decoration|align)-([^\\s]+)", "gi")
          , o = new RegExp("(border)-(top|right|bottom|left)-(style|color|width)-([^\\s]+)", "gi")
          , i = t.exec(e)
          , a = n.exec(e)
          , s = o.exec(e)
          , l = i || a || s;
        if (l) {
          var u = l.splice(l.length - 1)[0];
          l.shift();
          var c = l.map(function (e, t) {
            return t > 0 ? e.charAt(0).toUpperCase() + e.slice(1) : e
          }).join("");
          (c.indexOf("Size") > -1 || c.indexOf("Width") > -1) && (u = parseInt(u)),
            r[c] = u
        }
      }),
      n && (r.merge = !0),
      r
  }
  //同步工具栏状态
  static syncToolbarState(e) {
    var t = e.startRow
      , n = e.endRow
      , o = e.startCol
      , r = e.endCol
      , i = this.handsontableHelper.isMergeCell(e);
    if (t === n && o === r || i) {
      var a = this.hotInstance.getCellMeta(t, o)
        , s = this.handsontableHelper.judgeSignatureParam(t, o)
        , l = this.parseCellStyle(a.className || "", a.style || {}, i);
      this.emitter['syncToolbarState'] &&
        typeof this.emitter['syncToolbarState'] === 'function' &&
        this.emitter['syncToolbarState'](l, s)
    } else {
      this.emitter['syncToolbarState'] &&
        typeof this.emitter['syncToolbarState'] === 'function' &&
        this.emitter['syncToolbarState'](null)
    }
  }
  static compressCellBorderStyle(e, t) {
    if (!e)
      return null;
    for (var n in this.borders)
      if (isequal(e, this.borders[n]))
        return n;
    return this.borders[t] = e,
      t
  }

  // 更新列宽度
  static updateColumnWidth(e, t) {
    new ie(this.hotInstance, "alterTable", {
      colws: [{
        columnIndex: t,
        width: e
      }]
    }, "resizeColumn").commit()
  }

  // 更新行高度
  static updateRowHeight(e, t) {
    new ie(this.hotInstance, "alterTable", {
      rowhs: [{
        rowIndex: t,
        height: e
      }]
    }, "resizeColumn").commit()
  }

  //修改打印配置
  static setPageSetting(config) {
    this.pageSetting = config
    this.calcReferenceLine()
  }
  //撤销
  static undo() {
    const that = this
    if (!this.UndoRedoList.length) return
    this.isUndoRedo = this.UndoRedoList[0].isUndoRedo
    if (this.UndoRedoList[0] && this.UndoRedoList[0].revertChange) {
      if (typeof this.UndoRedoList[0].revertChange !== 'function' && this.UndoRedoList[0].revertChange.length) {
        this.UndoRedoList[0].revertChange.forEach(f => {
          f('UndoRedo.undo')
        })
        this.redoList.unshift({
          applyChange: [this.hotInstance.redo.bind(this), this.UndoRedoList[0].applyChange[1]],
          revertChange: this.UndoRedoList[0].revertChange,
          isUndoRedo: this.UndoRedoList[0].isUndoRedo
        })
      } else {
        this.UndoRedoList[0].revertChange('UndoRedo.undo')
        this.redoList.unshift(this.UndoRedoList[0])
      }
    }
    this.UndoRedoList.shift()
    window.isHandsonTableEdited = !0
    this.ToolbarHelper && this.ToolbarHelper.calculateEnable()
  }
  //重做
  static redo() {
    if (!this.redoList.length) return
    this.isUndoRedo = this.redoList[0].isUndoRedo
    // this.hotInstance.redo && this.hotInstance.redo()
    if (this.redoList[0] && this.redoList[0].applyChange) {
      if (typeof this.redoList[0].applyChange !== 'function' && this.redoList[0].applyChange.length) {
        this.redoList[0].applyChange.forEach(f => {
          f('UndoRedo.redo')
        })
        this.UndoRedoList.unshift({
          applyChange: this.redoList[0].applyChange,
          revertChange: [this.hotInstance.undo, this.redoList[0].revertChange[1]],
          isUndoRedo: this.redoList[0].isUndoRedo
        })
      } else {
        this.redoList[0].applyChange('UndoRedo.redo')
        this.UndoRedoList.unshift(this.redoList[0])
      }
    }
    this.redoList.shift()
    window.isHandsonTableEdited = !0
    this.ToolbarHelper && this.ToolbarHelper.calculateEnable()
  }
  //配置面板显隐  1全局配置 2二维码配置 3条码配置 4日期  5金额、数值
  static togglePanelShow(bol, type) {
    this.rightPanelInfo.rightVisible = bol
    this.rightPanelInfo.type = type
  }
  //配置面板更新数据
  static updateSettings(data) {
    const { row, col, type } = data
    const config = this.hotInstance.getSettings()
    const cellWithField = config.cellWithField
    switch (type) {
      case 1:
        this.hotInstance.updateSettings({
          serviceKey: data.serviceKey
        })
        break;
      case 2:
        const cellWithQRcode = config.cellWithQRcode
        cellWithQRcode && cellWithQRcode[`${row}:${col}`] && (cellWithQRcode[`${row}:${col}`] = Object.assign({}, cellWithQRcode[`${row}:${col}`], {
          content: data.content,
          contentType: data.contentType,
        }))
        this.hotInstance.updateSettings({
          cellWithQRcode: cellWithQRcode
        })
        this.hotInstance.render()
        break;
      case 3:
        const cellWithBRcode = config.cellWithBRcode
        cellWithBRcode && cellWithBRcode[`${row}:${col}`] && (cellWithBRcode[`${row}:${col}`] = Object.assign({}, cellWithBRcode[`${row}:${col}`], {
          codeType: data.codeType,
          content: data.content,
          contentType: data.contentType,
        }))
        this.hotInstance.updateSettings({
          cellWithBRcode: cellWithBRcode
        })
        this.hotInstance.render()
        break;
      case 4:
        cellWithField && cellWithField[`${row}:${col}`] && (cellWithField[`${row}:${col}`] = Object.assign({}, cellWithField[`${row}:${col}`], {
          FormatConfig: JSON.stringify({
            formatType: data.formatType,
            formatReg: data.formatReg,
          }),
        }))
        this.hotInstance.updateSettings({
          cellWithField: cellWithField
        })
        this.hotInstance.render()
        break;

      case 5:
        const configData = data.dataType === 'currency' ? {
          dataType: data.dataType,
          currencyType: data.currencyType,
          unit: data.unit,
          limitNumber: data.limitNumber,
          showSeparator: data.showSeparator,
        } : {
          dataType: data.dataType,
          unit: data.unit,
          limitNumber: data.limitNumber,
          showSeparator: data.showSeparator,
          isPercent: data.isPercent,
        }
        cellWithField && cellWithField[`${row}:${col}`] && (cellWithField[`${row}:${col}`] = Object.assign({}, cellWithField[`${row}:${col}`], {
          FormatConfig: JSON.stringify(configData),
        }))
        this.hotInstance.updateSettings({
          cellWithField: cellWithField
        })
        this.hotInstance.render()
        break;

      default:
        break;
    }
  }
  //单元格解析二维码、条形码数据
  static parseCellInfo({ row, col }) {
    this.updateCellUnit({
      startRow: row,
      startCol: col,
      endRow: row,
      endCol: col
    })
    const FORMAT_MAP = {
      DATE: {
        formatType: "datetimeSeconds",
        formatReg: "yyyy-MM-dd HH:mm",
      },
      NUMBER: {
        dataType: "number",
        unit: "",
        limitNumber: 0,
        showSeparator: false,
        isPercent: false,
      },
    }
    const QR = this.handsontableHelper.getCellWithQRcode(row, col)
    const BR = this.handsontableHelper.getCellWithBRcode(row, col)
    const cellExpression = this.handsontableHelper.getCellExpression(row, col)
    const Format = cellExpression ? cellExpression.Format : null
    let FormatConfig = cellExpression && cellExpression.FormatConfig ? JSON.parse(cellExpression.FormatConfig) : null
    if (FORMAT_MAP[Format] && !FormatConfig) {
      FormatConfig = JSON.stringify(FORMAT_MAP[Format])
    }
    let type = 1
    if (!!QR) {
      type = 2
    } else if (!!BR) {
      type = 3
    } else if (!!FormatConfig) {
      switch (Format) {
        case 'DATE':
          type = 4
          break;
        case 'NUMBER':
          type = 5
          break;
        default:
          break;
      }
    }
    const bool = !!QR || !!BR || !!FormatConfig || false
    this.togglePanelShow(bool, type)
    this.emitter['togglePanel'] && typeof this.emitter['togglePanel'] === 'function' && this.emitter['togglePanel']({ row, col, cellInfo: this.cellInfo }, QR || BR || FormatConfig || {}, type, bool)
    // this.emitter['toggleDisableToolbarItems'] && typeof this.emitter['toggleDisableToolbarItems'] === 'function' && this.emitter['toggleDisableToolbarItems'](bool)

  }

  //更新自定义字段list
  static updateCustomFieldList(list, fields = [], action) {
    this.hotInstance.updateSettings({
      customFieldList: list
    })
    //编辑更新引用的表格数据
    if (action === 'update') {
      const config = this.hotInstance.getSettings()
      let { expressions, cellWithField } = config
      for (let i = 0; i < expressions.length; i++) {
        for (let j = 0; j < fields.length; j++) {
          if (expressions[i].RootMetaDataID === fields[j].Expression) {
            expressions[i] = {
              ...expressions[i],
              Expression: fields[j].Expression,
              FieldLabel: fields[j].FieldLabel,
              MetaDataID: fields[j].Expression,
              RootMetaDataID: fields[j].Expression,
            }
          }
        }
      }
      for (let pos in cellWithField) {
        for (let j = 0; j < fields.length; j++) {
          if (cellWithField[pos].RootMetaDataID === fields[j].Expression) {
            cellWithField[pos] = {
              ...cellWithField[pos],
              Expression: fields[j].Expression,
              RootMetaDataID: fields[j].Expression,
            }
          }
        }
      }
      this.hotInstance.updateSettings({
        cellWithField: cellWithField,
        expressions: expressions
      })
    } else if (action === 'delete') {
      //暂时不处理
      // const config = this.hotInstance.getSettings()
      // let { expressions, cellWithField } = config
      // let index_expressions = expressions.findIndex((i) => i.RootMetaDataID === fields[0].Expression)
      // expressions.splice(index_expressions, 1)

      // for (let pos in cellWithField) {
      //   if (cellWithField[pos].RootMetaDataID === fields[0].Expression) {
      //     delete cellWithField[pos]
      //   }
      // }
      // this.hotInstance.updateSettings({
      //   cellWithField: cellWithField,
      //   expressions: expressions
      // })
    }
    this.hotInstance.render()
  }
}